package org.srishti.mobile;


import org.srishti.mobile.MySQLiteHelper;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class CommentsDataSource {

  // Database fields
	public static long insertId;
  private SQLiteDatabase database;
  private MySQLiteHelper dbHelper;
  private String[] allColumns = { MySQLiteHelper.COLUMN_ID,
  MySQLiteHelper.COLUMN_COMMENT,MySQLiteHelper.COLUMN_AGE,MySQLiteHelper.COLUMN_NUMBER };

  public CommentsDataSource(Context context) {
    dbHelper = new MySQLiteHelper(context);
  }

  public void open() throws SQLException {
    database = dbHelper.getWritableDatabase();
  }

  public void close() {
    dbHelper.close();
  }

  public long createComment(String comment,String age,String number) {
    ContentValues values = new ContentValues();
    values.put(MySQLiteHelper.COLUMN_COMMENT, comment);
    values.put(MySQLiteHelper.COLUMN_AGE, age);
    values.put(MySQLiteHelper.COLUMN_NUMBER, number);
    insertId = database.insert(MySQLiteHelper.TABLE_COMMENTS, null, values);
    
    return insertId;
       
  }


  public Cursor getComment(long insertId){
	  SQLiteDatabase db = dbHelper.getReadableDatabase();
	  Cursor cursor=db.query(MySQLiteHelper.TABLE_COMMENTS, allColumns, MySQLiteHelper.COLUMN_ID + " = " + insertId, null,
		        null, null, null);
	  
	  return cursor;
  }
  }
 
